package com.itcam.socket_;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Author:Cammy.Wu
 * Date:2024-05-15
 * Description:网络编程
 */

public class Demo01 {

    public static void main(String[] args) throws UnknownHostException {
        // 封装IP：
        // InetAddress ia = new InetAddress();不能直接创建对象，因为InetAddress()被default修饰
        InetAddress ia1 = InetAddress.getByName("192.168.1.12");
        System.out.println("ia1 = " + ia1);
        InetAddress ia2 = InetAddress.getByName("localhost"); // localhost指代的是本机的IP地址
        System.out.println("ia2 = " + ia2);
        InetAddress ia3 = InetAddress.getByName("127.0.0.1"); // 127.0.0.1指代的是本机的IP地址
        System.out.println("ia3 = " + ia3);
        InetAddress ia4 = InetAddress.getByName("Nuyoah"); // 封装计算机名
        System.out.println("ia4 = " + ia4);
        InetAddress ia5 = InetAddress.getByName("www.baidu.com"); // 封装域名
        System.out.println("ia5 = " + ia5);

        System.out.println(ia5.getHostName()); // 获取域名
        System.out.println(ia5.getHostAddress()); // 获取IP地址
    }
}
